//
//  WelcomeVC.m
//  ocCrazy
//
//  Created by mac on 2018/6/27.
//  Copyright © 2018年 dukai. All rights reserved.
//

#import "WelcomeVC.h"
#import "WelcomeCell.h"
#import "AppDelegate.h"
#import "BaseTabBarVC.h"
#import "BaseNavigationVC.h"
#import "ZYXLoginViewController.h"
@interface WelcomeVC ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (strong,nonatomic)UICollectionViewFlowLayout *flowLayout;

@end

@implementation WelcomeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    if (@available(iOS 11.0, *)) {
        self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }

}

-(void)setupViews{
    _flowLayout = [[UICollectionViewFlowLayout alloc]init];
    _flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
    _flowLayout.minimumLineSpacing = 0;
    _flowLayout.minimumInteritemSpacing = 0;
    _flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
   self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:self.flowLayout];
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.delegate = self;
     self.collectionView.dataSource = self;
    self.collectionView.pagingEnabled = YES;
    [self.collectionView registerNib:[UINib nibWithNibName:@"WelcomeCell" bundle:nil] forCellWithReuseIdentifier:@"WelcomeCell"];
    [self.view addSubview:self.collectionView];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    WelcomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WelcomeCell" forIndexPath:indexPath];
    NSString *str = [NSString stringWithFormat:@"yd_%ld.jpg",indexPath.item + 1];
    cell.image.image = [UIImage imageNamed:str];
    return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.item == 2) {
//        [UIApplication sharedApplication].keyWindow.rootViewController = [BaseTabBarVC new];
        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"firstIn"];
        ZYXLoginViewController *ctrl = [[ZYXLoginViewController alloc] init];
        BaseNavigationVC *nav = [[BaseNavigationVC alloc] initWithRootViewController:ctrl];
        [UIApplication sharedApplication].keyWindow.rootViewController = nav;
    }
}

@end
